// @ts-nocheck
import http from '@ohos.net.http';
//文件中的几个方法实现不好，只是为了体现效果，之后会重写滴
let InternetArray=[]

function Httpreq(){
    let httpRequest = http.createHttp();
    // 用于订阅http响应头，此接口会比request请求先返回。可以根据业务需要订阅此消息
    // 从API 8开始，使用on('headersReceive', Callback)替代on('headerReceive', AsyncCallback)。 8+
    httpRequest.on('headersReceive', (header) => {
        console.info('header: ' + JSON.stringify(header));
    });
    httpRequest.request(
        // 填写http请求的url地址，可以带参数也可以不带参数。URL地址需要开发者自定义。请求的参数可以在extraData中指定
        "http://81.71.71.125:8080/api/v1/front/getAction/head?version=v1.0",
        {
            method: http.RequestMethod.GET, // 可选，默认为http.RequestMethod.GET
            // 开发者根据自身业务需要添加header字段
            header: {
                'Content-Type': 'application/json'
            },
            // 当使用POST请求时此字段用于传递内容
            connectTimeout: 60000, // 可选，默认为60s
            readTimeout: 60000, // 可选，默认为60s
        }, (err, data) => {
        if (!err) {
            // data.result为http响应内容，可根据业务需要进行解析
            console.info('Result:' + data.result);
            //InternetArray=data.result
            console.info('code:' + data.responseCode);
            // data.header为http响应头，可根据业务需要进行解析
            console.info('header:' + JSON.stringify(data.header));
            console.info('cookies:' + data.cookies); // 8+
        } else {
            console.info('error:' + JSON.stringify(err));
            // 当该请求使用完毕时，调用destroy方法主动销毁。
            httpRequest.destroy();
        }
    }
    );
}
export class WPNoteClass { //---在主界面调用数据库
    rdbStore
    constructor(rdbStore) {
        this.rdbStore=rdbStore
    }

    query(cb) { //---查询所有值
        let self = this
        this.rdbStore.queryValue('NOTES', (resultSet) => { //查找操作与查询操作不同但对结果集处理相同
            self.resultSetServer(resultSet, (contactList) => { //---处理结果集
                cb(contactList) //---结果解析后放入contactList回调
            })
        })
    }

    update(obj, id, cb) { //---更新
        this.rdbStore.updateValue(obj, 'NOTES', 'ID', id)
        cb()
    }

    insert(obj, cb) { //---插入
        //        let obj = { //--- 例：一行数据格式示例
        //            title:'111',
        //            content:'222'
        //        }
        this.rdbStore.insertValue('NOTES', obj) //---按顺序插入一行数据（ID自动自增）
        cb()
    }

    deleteVal(cb) { //---删除
        this.rdbStore.deleteValue('NOTES', 'ID', 1) //--- 例：删除ID为1的那一行数据
        cb()
    }

    search(cb) { //---查询特定值
        var self = this
        this.rdbStore.searchValue('NOTES', 'TITLE', 'title_example', (resultSet) => { //--- 例：查询TILTLE名为title_example的那一行数据
            self.resultSetServer(resultSet, (contactList) => { //---处理结果集
                cb(contactList)
            })

        })
    }

    resultSetServer(resultSet, cb) { //--- 例：结果集resultSet的处理函数
        let contactList = []
        console.log(JSON.stringify(resultSet.rowCount) )
        if (resultSet.rowCount > 0) { //--- rowCount为resultSet包含的行数
            console.log('-----------in if-----------');
            while (resultSet.goToNextRow()) { //--- 不断读取下一行数据直至读完
                let id = resultSet.getLong(resultSet.getColumnIndex("ID")); //--- ID为整型，使用getLong获取
                let title = resultSet.getString(resultSet.getColumnIndex("TITLE")); //--- TITLE为文本型，使用getString获取
                let content = resultSet.getString(resultSet.getColumnIndex("CONTENT")); //--- CONTENT为文本型，使用getString获取
                let obj = {
                    id: id,
                    title: title,
                    content: content
                };
                contactList.push(obj);
            }
            if (contactList.length > 0) {
                console.info('xxx--- query suc length = ' + contactList.length)
            }
        } else {
            console.info('xxx--- query empty')
        }
        resultSet.close(); //---记得关闭结果集
        resultSet = null;
        cb(contactList)
    }
}

export class goods{
    //商品类
    #info
    constructor(info){
        this.#info=info;
    }
    getgoodsArray(contactList){
        //InternetArray=null
        //暂时无法测试数据请求
        //Httpreq()
        let InternetArray=contactList
        InternetArray=[            {id:1,WPname:'phone1',WPprice:4000,WPpicture:'../../common/images/WPpicture/WP1'},
                                   {id:2,WPname:'phone2',WPprice:5000,WPpicture:'../../common/images/WPpicture/WP2'},
                                   {id:3,WPname:'phone3',WPprice:6000,WPpicture:'../../common/images/WPpicture/WP3'},
                                   {id:3,WPname:'phone3',WPprice:6000,WPpicture:'../../common/images/WPpicture/WP3'},
                                   {id:3,WPname:'phone3',WPprice:6000,WPpicture:'../../common/images/WPpicture/WP3'},
                                   {id:3,WPname:'phone3',WPprice:6000,WPpicture:'../../common/images/WPpicture/WP3'},
                                   {id:3,WPname:'phone3',WPprice:6000,WPpicture:'../../common/images/WPpicture/WP3'},
                                   {id:3,WPname:'phone3',WPprice:6000,WPpicture:'../../common/images/WPpicture/WP3'},
                                   {id:3,WPname:'phone3',WPprice:6000,WPpicture:'../../common/images/WPpicture/WP3'},
                                   {id:3,WPname:'phone3',WPprice:6000,WPpicture:'../../common/images/WPpicture/WP3'},
                                   {id:3,WPname:'phone3',WPprice:6000,WPpicture:'../../common/images/WPpicture/WP3'},
                                   {id:3,WPname:'phone3',WPprice:6000,WPpicture:'../../common/images/WPpicture/WP3'},
                                   {id:3,WPname:'phone3',WPprice:6000,WPpicture:'../../common/images/WPpicture/WP3'},
                                   {id:3,WPname:'phone3',WPprice:6000,WPpicture:'../../common/images/WPpicture/WP3'},
                                   {id:3,WPname:'phone3',WPprice:6000,WPpicture:'../../common/images/WPpicture/WP3'},
                                   {id:3,WPname:'phone3',WPprice:6000,WPpicture:'../../common/images/WPpicture/WP3'},
                                   {id:3,WPname:'phone3',WPprice:6000,WPpicture:'../../common/images/WPpicture/WP3'},
                                   {id:3,WPname:'phone3',WPprice:6000,WPpicture:'../../common/images/WPpicture/WP3'},
                                   {id:3,WPname:'phone3',WPprice:6000,WPpicture:'../../common/images/WPpicture/WP3'},
                                   {id:3,WPname:'phone3',WPprice:6000,WPpicture:'../../common/images/WPpicture/WP3'},
                                   {id:3,WPname:'phone3',WPprice:6000,WPpicture:'../../common/images/WPpicture/WP3'},
                                   {id:3,WPname:'phone3',WPprice:6000,WPpicture:'../../common/images/WPpicture/WP3'},
                                   {id:3,WPname:'phone3',WPprice:6000,WPpicture:'../../common/images/WPpicture/WP3'},
                                   {id:3,WPname:'phone3',WPprice:6000,WPpicture:'../../common/images/WPpicture/WP3'},
                                   {id:3,WPname:'phone3',WPprice:6000,WPpicture:'../../common/images/WPpicture/WP3'},
                                   {id:3,WPname:'phone3',WPprice:6000,WPpicture:'../../common/images/WPpicture/WP3'},
                                   {id:3,WPname:'phone3',WPprice:6000,WPpicture:'../../common/images/WPpicture/WP3'},
                                   {id:3,WPname:'phone3',WPprice:6000,WPpicture:'../../common/images/WPpicture/WP3'},
                                   {id:3,WPname:'phone3',WPprice:6000,WPpicture:'../../common/images/WPpicture/WP3'},
                                   {id:3,WPname:'phone3',WPprice:6000,WPpicture:'../../common/images/WPpicture/WP3'},
                                   {id:3,WPname:'phone3',WPprice:6000,WPpicture:'../../common/images/WPpicture/WP3'},
                                   {id:3,WPname:'phone3',WPprice:6000,WPpicture:'../../common/images/WPpicture/WP3'},
                                   {id:4,WPname:'phone4',WPprice:7000,WPpicture:'../../common/images/WPpicture/WP4'}

        ]//随便加点数据
        return InternetArray
    }
}

export function swiperToo(id,value,a){
    //点击按钮切换不同商品界面（例如：商城->仓库）
        value=value-1
        console.info('index:'+value)
        console.info('id='+id)
        a.swipeTo({index: value});
}
export function WPclick(){
//物品点击事件，例如选中购买，点击出现详情。。。。。。
    //未实现
        this.WPselected++
        console.info('已选中,选中数：'+this.WPselected)


}
